import websocket
import json

def on_message(ws, message):
    print(message)

def on_error(ws, error):
    print(error)

def on_close(ws, close_status_code, close_msg):
    print("Connection closed")

def on_open(ws):
    print("Connection established")

    data = {
        "eventName": "subscribe",
        "eventData": {
            "channel": "my_channel"
        }
    }
    ws.send(json.dumps(data))
# -------------------------------------------------- v1 url wss://feeds.prod.blur.io/socket.io/?tabId=pKzRU7SRBQDn&storageId=n3kEOR5uxjEF&EIO=4&transport=websocket -------------------------------------------------------#
url = "wss://feeds.prod.blur.io/socket.io/?tabId=pKzRU7SRBQDn&storageId=n3kEOR5uxjEF&EIO=4&transport=websocket"
#0{"sid":"1yEDuLcyM5PlCI4StBfh","upgrades":[],"pingInterval":25000,"pingTimeout":20000}
# -------------------------------------------------- v2 url wss://feeds.prod.blur.io/socket.io/ -------------------------------------------------------#
# url = "wss://feeds.prod.blur.io/socket.io/"
# Connection established
# rsv is not implemented, yet
ws = websocket.WebSocketApp(url,
                            on_message=on_message,
                            on_error=on_error,
                            on_close=on_close,
                            on_open=on_open)

ws.run_forever()